const path = require('path')

const utils = require('./utils')
const webpack = require('webpack')
const nodeExternals = require('webpack-node-externals')
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

// debugger;

const webpackconfig = {
  target: 'node',
  entry: {
    server: path.join(utils.APP_PATH, '/index.js') // 入口文件
  },
  output: {
    filename: '[name].bundle.js',
    path: utils.DIST_PATH // 打包之后存放的目录
  },
  module: {
    rules: [
      {
        test: /\.(js|jsx)$/, // 匹配目录下所有 js 文件
        use: {
          loader: 'babel-loader'
        },
        exclude: [path.join(__dirname, 'node_modules')] // 排除文件夹
      }
    ]
  },
  externals: [nodeExternals()],
  plugins: [
    new CleanWebpackPlugin(),
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'prod' ? '"production"' : "'development'")
      }
    })
  ]/* ,
  node: {
    console: true,
    global: true,
    process: true,
    Buffer: true,
    __filename: true,
    __dirname: true,
    setImmediate: true,
    path: true  
  } */
}
// console.log(webpackconfig.node)

module.exports = webpackconfig

